#!-*-coding: utf-8 -*-
"""
房间
"""


class Room:
    def __init__(self, user, room_name):
        self.__room_name = room_name
        self.__room_owner = user    # 房间创建者为房主
        self.__member_list = []
        self.__member_list.append(user) # 将房间创建者加入成员列表

    def get_name(self):
        """
        desc:   获取房间名
        param:  空
        return:
            str:    房间名
        """
        return self.__room_name

    def has_user(self, user):
        """
        desc:   判断用户是否在该房间中
        param:
            user:   用户
        return:
            bool:   用户是否在房间中
        """
        res = user in self.__member_list
        return res

    def add_user(self, user):
        """
        desc:   将用户添加至该房间中
        param:
            user:   用户
        return: 空
        """
        self.__member_list.append(user)

    def empty(self):
        """
        desc:   判断房间是否为空
        param:
            user:   用户
        return:
            bool:   房间是否为空
        """
        return len(self.__member_list) == 0

    def member_count(self):
        """
        desc:   房间内用户数量
        param:  空
        return:
            int:   用户数量
        """
        return len(self.__member_list)

    def get_members(self):
        """
        desc:   获取房间的所有用户
        param:  空
        return:
            list:   用户列表
        """
        return self.__member_list

    def remove_member(self, user):
        """
        desc:   移除房间内指定的用户
        param:
            user:   待移除的用户
        return:
        """
        self.__member_list.remove(user)
        if user == self.__room_owner:
            # 将房主转让给下一个最早进入房间的人
            if len(self.__member_list) > 0:
                self.__room_owner = self.__member_list[0]
            else:
                self.__room_owner = None

